package com.atguigu.flink03;

import com.atguigu.beans.WaterSensor;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2024/2/20
 * 该案例演示了过滤算子
 * 将数据流中传感器id为sensor_1的数据过滤出来
 */
public class Flink09_Trans_Filter {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<WaterSensor> stream = env.fromElements(
                new WaterSensor("sensor_1", 1L, 1),
                new WaterSensor("sensor_1", 2L, 2),
                new WaterSensor("sensor_2", 2L, 2),
                new WaterSensor("sensor_3", 3L, 3)
        );

       /* stream.filter(
                new FilterFunction<WaterSensor>() {
                    @Override
                    public boolean filter(WaterSensor ws) throws Exception {
                        return "sensor_1".equals(ws.id);
                    }
                }
        ).print();*/

        stream.filter(
                ws->"sensor_1".equals(ws.id)
        ).print();

        env.execute();
    }
}
